﻿/* ----------------------------------------------------------------------------
 * Copyright (c) Philip Stears 
 *
 * This source code is subject to terms and conditions of the Microsoft Public 
 * License (Ms-PL).
 * 
 * By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 * 
 * To request a copy of the Microsoft Public License, send a request by email
 * to license@connectbasic.net.
 *
 * This notice must not be removed from this software.
 * ---------------------------------------------------------------------------- */

namespace ConnectBasic.ObjectModel
{
    using System.ComponentModel;
    using System.Diagnostics;
    using Microsoft.Scripting;

    /// <summary>
    /// Represents an expression.
    /// </summary>
    [DebuggerDisplay("{GetDebuggerDisplay(),nq}")]
    public abstract class ExpressionBase : NodeBase
    {
        private SourceSpan mSpan;
        
        /// <summary>
        /// Initializes a new instance of the <see cref="ExpressionBase" /> class.
        /// </summary>
        /// <param name="expressionSpan">
        /// The span which describes the span in the source text from which the 
        /// expression was derived.
        /// </param>
        public ExpressionBase(SourceSpan expressionSpan)
        {
            mSpan = expressionSpan;
        }

        /// <summary>
        /// Gets the span which describes the span in the source text from which the 
        /// expression was derived.
        /// </summary>
        public SourceSpan Span
        {
            get { return mSpan; }
        }

        /// <summary>
        /// Gets a debugging string.
        /// </summary>
        /// <returns></returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification="Potentially expensive operation")]
        [EditorBrowsable(EditorBrowsableState.Advanced)]
        public abstract string GetDebuggerDisplay();

        /// <summary>
        /// For debugging, returns a string representation of the expression.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return this.GetDebuggerDisplay();
        }
    }
}
